package com.tueye.web.controller;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;

import com.tueye.entity.TopicType;
import com.tueye.service.ITopicTypeService;


@SuppressWarnings("unchecked")
@org.springframework.stereotype.Controller
@RequestMapping("/topicType.do")
public class TopicTypeController {
	
	@Autowired
	@Qualifier("topicTypeService")
	ITopicTypeService topicTypeService;
	
	@RequestMapping(params = "action=getData")
	public String getTreeNode (HttpServletRequest request, HttpServletResponse response) throws IOException{
		//String jsonStr ="[{ data : 'ooooo ooo node', children : [ { data : 'Only child' } ], state : 'open' },{ data : 'Some other node' }]";
		String id = (String)request.getParameter("id");
		System.out.println("^&^&^&^^&*&^*&&::" + id );
		String jsonStr = topicTypeService.getData();
		//String jsonStr = topicTypeService.getData();
		response.setContentType("html/txt");
		response.setCharacterEncoding("utf-8");
		response.getWriter().println(jsonStr);
		return null;
	}
	
	@RequestMapping(params = "action=updateNode")
	public String updateNode (HttpServletRequest request, HttpServletResponse response) throws IOException{
		//String jsonStr ="[{ data : 'ooooo ooo node', children : [ { data : 'Only child' } ], state : 'open' },{ data : 'Some other node' }]";
		String id = (String)request.getParameter("id");

		String typeName = (String)request.getParameter("typeName");
		String typeEnlishName =(String)request.getParameter("typeEnlishName");
		String typeDesc =(String)request.getParameter("typeDesc");
		String typePageKey =(String)request.getParameter("typePageKey");
		String typePageTitle=(String)request.getParameter("typePageTitle");
		
		System.out.println("MM------modifyNode----id:"+id+"---:-----");
		String []vlaue = {id,typeName,typeEnlishName,typeDesc,typePageKey,typePageTitle};
		if(id != null && !"".equals(id))
		{
			topicTypeService.updateTopicType(vlaue);
		}
		response.setContentType("html/txt");
		response.setCharacterEncoding("utf-8");
		response.getWriter().println("");
		return null;
	}
	
	@RequestMapping(params = "action=addNode")
	public String addNode (HttpServletRequest request, HttpServletResponse response) throws IOException{
		//String jsonStr ="[{ data : 'ooooo ooo node', children : [ { data : 'Only child' } ], state : 'open' },{ data : 'Some other node' }]";
		String pid = (String)request.getParameter("pid");
		String typeName = (String)request.getParameter("typeName");
		String typeEnlishName =(String)request.getParameter("typeEnlishName");
		String typeDesc =(String)request.getParameter("typeDesc");
		String typePageKey =(String)request.getParameter("typePageKey");
		String typePageTitle=(String)request.getParameter("typePageTitle");
		
		System.out.println("CC------createNode(::)-pid:" + pid);
		System.out.println("------------:typeName:" + typeName);
		System.out.println("------------:typeEnlishName:" + typeEnlishName);
		System.out.println("------------:typeDesc:" + typeDesc);
		System.out.println("------------:typePageKey:" + typePageKey);
		System.out.println("------------:typePageTitle:" + typePageTitle);
		String [] value={pid,typeName,typeEnlishName,typeDesc,typePageKey,typePageTitle};
		String st = topicTypeService.addTopicType(value);
		
		//String jsonStr = getJsonString(st);
		System.out.println("--我的id是：-------" + st);
		response.setContentType("html/txt");
		response.setCharacterEncoding("utf-8");
		response.getWriter().println(st);
		return null;
	}
	
	@RequestMapping(params = "action=deleteNode")
	public String deleteNode (HttpServletRequest request, HttpServletResponse response) throws IOException{
		//String jsonStr ="[{ data : 'ooooo ooo node', children : [ { data : 'Only child' } ], state : 'open' },{ data : 'Some other node' }]";
		String pid = (String)request.getParameter("pid");
		String id = (String)request.getParameter("id");
		System.out.println("DD------deleteNode(::)-"+id+"-----------");
		String []value = {id,""};
		topicTypeService.deleteTopicType(value);
		response.setContentType("html/txt");
		response.setCharacterEncoding("utf-8");
		response.getWriter().println("");
		return null;
	}
	@RequestMapping(params = "action=getNodeInfor")
	public String getNodeInfor(HttpServletRequest request, HttpServletResponse response) throws IOException{
		String id = (String)request.getParameter("id");
		System.out.println("DD------getInfor(::)-"+id+"-----------");
		String returnStr = topicTypeService.getNodeInforById(id);
		System.out.println("-returnStr----------" + returnStr);
		response.setContentType("html/txt");
		response.setCharacterEncoding("utf-8");
		response.getWriter().println(returnStr);
		return null;
	}
}
